<template>
      <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple" @grid-ready="gridReady" style="height:100%" class='ag-theme-alpine'
        :defaultColDef="defaultColDef" :rowData="table.dataList" :columnDefs="cfsValue" :localeText="localeTextData" />
    <paginationCopys :total="total" show-total show-jumper show-page-size @change="changePage" @page-size-change="changeSize"
        style="justify-content: center;margin-top: 10px;" :page-size="pagination.pageSize" :current="pagination.page" />
</template>
<script lang="ts">

import { localeText } from '@/api/aggridZw'
import emitter from "@/hooks/useEventBus";
import { onMounted, reactive, ref } from 'vue';
import { usePagination, useTable } from '@/hooks/table';
import { verifyManage } from '@/api/PhysicalSurveyRoom/physicalTestApi';
import { Message } from '@arco-design/web-vue';
import { assTable } from '@/utils/assemblyLevelTable';
export default { 
    name: 'phyManageUnApproved',
    components: {  },
    props: {
        searchData: {
            type: Object,
            default: () => { }
        },
        auditIds: {
            type: Array,
            default: () => []
        },
    },
    setup(props, { emit }) {
        const table = useTable();
        const pageData = reactive<{
            pageLoading: boolean,
        }>({
            pageLoading: false
        });
        const verifyManageApi = verifyManage();
        emitter.on("refresh-phyManageUnApproved", () => {
            doRefresh();
            pagination.page = 1;
        });
        const doRefresh = async () => {
            pageData.pageLoading = true;
            await verifyManageApi.getQueryVerifyManageList({
                page: pagination.page,
                size: pagination.pageSize,
                ...props.searchData,
                auditState: 0
            }).then(({ code, data }: any) => {
                if (code === 200) {
                    // console.log(data);
                    table.handleSuccess(data.list);
                    gridOption.value.setRowData(data.list);
                    total.value = data.total;
                } else {
                    Message.error('数据查询失败')
                }
            }).catch(console.log).finally(() => {
                pageData.pageLoading = false;
            });

        };
        const pagination = usePagination(doRefresh);
        //表格方面
        const gridOption = ref();
        const gridReady = (params: any) => {
            gridOption.value = params.api;
            //调整表格自适应大小
        }
        const defaultColDef = {
            sortable: true,
            resizable: true,
            filter: true,
            width: 150
            // flex: 1
        }
        let cfsValue: any = [
            {
                headerName: "部门",
                field: "department",
            },
            {
                headerName: "日期(DATE)",
                field: "verifyManageDate",
                width: 170,
            },
            {
                headerName: "流转卡号(LOT#)",
                field: "circulatCard",
            },
            {
                headerName: "不合格项目",
                field: "unqualifiedProject",
            },
            {
                headerName: "记录单号(NO)",
                field: "verifyManageCode",
            },
            {
                headerName: "计划单号",
                field: "planCode",
            },
            {
                headerName: "客户名称",
                field: "customName",
            },
            {
                headerName: "布号",
                field: "clothCode",
            },
            {
                headerName: "品名",
                field: "brandName",
            },
            {
                headerName: "纱支",
                field: "yarnCount",
            },
            {
                headerName: "色号",
                field: "colorCode",
            },
            {
                headerName: "色称",
                field: "colorName",
            },
            {
                headerName: "设备编号",
                field: "deviceCode",
            },
            {
                headerName: "缸型",
                field: "depart",
            },
            {
                headerName: "重量",
                field: "weight",
            },
            {
                headerName: "匹数",
                field: "pieceNum",
            },
            {
                headerName: "坯布编号",
                field: "greyCode",
            },
            {
                headerName: "结果",
                field: "verifyResult",
                cellRenderer: {
                    template: `{{verifyResult == 0 ? '合格' : verifyResult == 1 ? '不合格' : 'REJ让步'}}`,
                    setup(props: any) {
                        let verifyResult = props.params.data.verifyResult;
                        return {
                            verifyResult
                        }
                    }
                }
            },
            {
                headerName: "横缩(挂干)",
                field: "abscissHangDry",
            },
            {
                headerName: "直缩(挂干)",
                field: "straightHangDry",
            },
            {
                headerName: "扭度(挂干)",
                field: "torsionHangDry",
            },
            {
                headerName: "洗后克重(挂干)",
                field: "washWeightHangDry",
            },
            {
                headerName: "横缩(抛干)",
                field: "abscissThrowDry",
            },
            {
                headerName: "直缩(抛干)",
                field: "straightThrowDry",
            },
            {
                headerName: "扭度(抛干)",
                field: "torsionThrowDry",
            },
            {
                headerName: "洗后克重(抛干)",
                field: "washWeightThrowDry",
            },
            {
                headerName: "横缩(平干)",
                field: "abscissFlatDry",
            },
            {
                headerName: "直缩(平干)",
                field: "straightFlatDry",
            },
            {
                headerName: "扭度(平干)",
                field: "torsionFlatDry",
            },
            {
                headerName: "洗后克重(平干)",
                field: "washWeightFlatDry",
            },
            {
                headerName: "备注",
                field: "remark",
            },
            {
                headerName: "要求",
                field: "depart",
                children: [
                    {
                        headerName: "克重",
                        field: "requireWeight",

                    },
                    {
                        headerName: "门幅",
                        field: "measuredWidth",

                    },
                ]
            },
            {
                headerName: "实测",
                field: "depart",
                children: [
                    {
                        headerName: "克重",
                        field: "measuredWeight",

                    },
                    {
                        headerName: "门幅",
                        field: "measuredWidth",

                    },
                    {
                        headerName: "米长",
                        field: "depart",

                    },
                ]
            },
            {
                headerName: "PH值",
                field: "depart",
            },
            {
                headerName: "建立人",
                field: "createName",
            },
            {
                headerName: "建立日期",
                field: "createTime",
                width: 170,
            },

            {
                headerName: "审核状态",
                field: "auditState",
                cellRenderer: {
                    template: `<div>未审核</div>`,
                }
            },
            {
                headerName:'操作',
                field:'options',
                pinned:'right',
                lockPosition: "right",
                cellRenderer:{
                    template:'<el-button style="color:#156dff" @click="a" link>编辑</el-button>',
                    setup({params}:any) {
                        const a = () => { 
                            toRowClick(params.data)
                        };
                        return {
                            a
                        }
                    }
                }
             }
        ];
        let a = [{
            showRowGroup: 'hide_def',
            "headerName": "",
            "checkboxSelection": true,
            "headerCheckboxSelection": true,
            "pinned": "left",
            "width": 50,
            resizable: false,
            filter: false,
            sortable: false,
            minWidth: 50,
            maxWidth: 50,
            lockPosition: "left",
        }]
        cfsValue = a.concat(cfsValue);
        const total = ref(10);
        const changePage = (val: any) => {
            pagination.page = val
            doRefresh();
        }
        const changeSize = (val: any) => {
            pagination.pageSize = val
            doRefresh();
        }

        const localeTextData: any = ref(localeText);

        emitter.on('changUnApprovedRows', () => {
            let idsArr = gridOption.value.getSelectedRows();
            emit('has-audit', idsArr);
        });
        emitter.on('delShanc', () => {
            let idsArr = gridOption.value.getSelectedRows();
            emitter.emit('hasDel', idsArr);
        });
        emitter.on('export-phyManageUnApproved', () => {
            let selectList = gridOption.value.getSelectedRows(); 
            if (selectList.length === 0) {
                Message.error('请勾选需要导出的数据')
                return
            } else {
                let nowRow = table.dataList.filter(function (o) {
                    return (gridOption.value.getSelectedRows().map((o: any) => { return o.id })).indexOf(o["id"]) !== -1;
                })
                assTable(cfsValue, nowRow, '物测管理');
            }
        });
        emitter.on("print-phyManageUnApproved",() => {
            let selectList = gridOption.value.getSelectedRows(); 
            if (selectList.length === 0) {
                Message.error('请勾选需要打印的数据')
                return
            } else {
                let data = selectList[0];
                emit('print-click',data);
            }
        })
        const toRowClick = (data:any) => {
            emit('edit-click',data)
        }
        return { 
            pagination,
            table,
            localeTextData,
            changePage,
            changeSize,
            total,
            cfsValue,
            defaultColDef,
            gridReady,
            toRowClick
        }
    },
}
</script>
<style lang="less" scoped></style>